using System;
using System.Collections.Generic;
using System.Text;

using MVCFramework.Models;
using BuildingBasicDomain;
using MVCFramework.Presenter.Selections;


namespace MVCFramework.Presenter.Commands
{

    /// <summary>
    /// deleting selcted elements is encapsulated in here 
    /// existing Commands  is used .
    /// </summary>
    internal class DeleteSelectionCommand : Command 
    {
        private IModel _construction;
        private Selection _selection;
        private List<Command> _commands;

        public DeleteSelectionCommand(IModel _construction, Selection _selection)
        {
            this._construction = _construction;
            this._selection = _selection;
            _commands = new List<Command>();
                        
        }

        public override bool Execute()
        {   
            Command currentCommand;
            foreach (ISelectable current in _selection)
            {
                    current.IsSelected = false;
                    currentCommand = new RemoveObjcetCommand <ISelectable> (_construction,current);
                    if (currentCommand.Execute())
                        _commands.Add(currentCommand);
            }

            _selection.Clear();
            return true;
        }
        public override bool UnExecute()
        {
            foreach (Command currentCommand in _commands)
                currentCommand.UnExecute();
       
            return true;
        }

        public override string Description
        {
            get
            {
                return "Delete Selected Objects";
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }
    }

}
